package com.visizen.wisdomclass.server.action.User;

import com.alibaba.fastjson.JSONObject;
import com.visizen.wisdomclass.server.action.response.Result;
import com.visizen.wisdomclass.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 【用户】 查询指定手机号码是否被注册
 *
 * @author: chenjian
 */
@Controller
@RequestMapping("/User")
public class UserCheckMobilePhoneAction {
    /**
     * 查询指定手机号码是否被注册
     *
     * @param token
     * @param mobilephone 用户名
     * @param request
     * @return
     */
    @RequestMapping(value = "/checkMobilePhoneExist", method = RequestMethod.GET)
    @ResponseBody
    public Result checkMobilePhoneExist(@RequestParam(required = false) String token,
                                        @RequestParam(required = true) String mobilephone,
                                        HttpServletRequest request) {
        Result result = new Result();
        JSONObject jo = new JSONObject();
        boolean isExist = userService.checkUserExistByMobilePhone(mobilephone);
        jo.put("Exist", isExist);
        result.setSuccessResult(request, "", jo);
        return result;
    }

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
